<?php

namespace App\Controller\App;

use App\Base\BaseController4Restful;
use App\Entity\Task;
use App\Entity\Usercontact;
use App\Repository\UsercontactRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

/**
 * @route("/app")
 */
class UserTaskController extends BaseController4Restful
{
    /**
     * @Route("/user/task", name="AppUserTask",methods={"GET","POST"})
     */
    public function AppUserTask(Request $request)
    {
        $user = $this->needToBeUser();
        if ($request->getMethod() == "GET") {
            $tasks = $user->getTasks(1);
            $this->setGroups("task");
            return $this->json_out(200,"获取成功",$tasks);
        }else{
            return $this->json_out(500,"系统错误");
        }
    }
    /**
     * @Route("/task/{id}", name="AppUserTaskInfo",methods={"GET"})
     */
    public function AppUserTaskInfo(Task $task,Request $request)
    {
//        $user = $this->needToBeUser();
        if ($task) {
            $this->setGroups("task");
            return $this->json_out(200,"获取成功",$task);
        }
    }

    /**
     * @Route("/task/{id}/check/vote", name="AppUserTaskInfoCheckVote",methods={"GET"})
     */
    public function AppUserTaskInfoCheckVote(Task $task,Request $request)
    {
        $user = $this->getUser();
        $votes = $task->getVote();
        $find = 0;
        foreach ($votes as $vote) {
            if ($vote->getUser() == $user) {
                $find = $vote->getPrice();
            }
        }
        return $this->json_out(200,"OK",$find);
    }
}
